package com.zyy.smartcity1129.bus;

import android.app.DatePickerDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.util.DateStringUtil;

import java.util.Date;

/**
 * @ClassName: BusDateFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 5/12/2021$
 * @Version: 1.0
 */
public class BusDateFragment extends BaseFragment {
    private ImageView imageView2;
    private TextView textView11;
    private Button button5;
    public static String date;

    @Override
    protected int layId() {
        return R.layout.f_busdate;
    }

    @Override
    protected String title() {
        return "日历日期";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return false;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        BusFragment.liveData.observe(getViewLifecycleOwner(), m -> {
            remove();
        });
        String now = DateStringUtil.dateToString(new Date());
        date = now;
        textView11.setText(DateStringUtil.stringToYYMMDD(now));
        imageView2.setOnClickListener(view -> {
            new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    textView11.setText(i + "-" + (i1 + 1) + "-" + i2);
                    date = i + "-" + (i1 + 1) + "-" + i2;
                }
            }, 2021, 12, 1).show();
        });
        button5.setOnClickListener(view -> {
                add(new BusUpDownFragment());
        });
    }

    private void initView(View iv) {
        imageView2 = (ImageView) iv.findViewById(R.id.imageView2);
        textView11 = (TextView) iv.findViewById(R.id.textView11);
        button5 = (Button) iv.findViewById(R.id.button5);
    }
}
